<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>

<!DOCTYPE>
<html>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>

    <style type="text/css">
        .drop-title{
            height: 35px;
            background-color: rgb(99,181,218);
            line-height: 40px;
            padding: 0px 10px;
            font-size: 12px;
            margin-left: 5px;
            /*border-radius: 5px 5px 0 0;*/
            color: #fff;
        }
        .app_table{
            width:98%;
            margin:5px auto;
            border:1px solid #d9d9d9;
            border-collapse: collapse;
            empty-cells: show;
        }
        .app_table tr{
            width:100%;
        }
        .app_table tr td{
            border:1px solid #d9d9d9;
            height:32px;
            text-align:left;
            text-indent:10px;
            line-height:32px;
            border-collapse: collapse;
            empty-cells: show;
            color:#647487;
        }
        .app_table tr td a{
            color:#647487;
            cursor:pointer;
        }
        .app_table tr td a:hover{
            color:#3195d4;
        }
    </style>
    <script type="text/javascript">
        //保存
        function saveRestrictAuth(){
            var resFieldId = $("input[name='resField']:checked").val();
            var pidresFieldId = "${restricterId}";
            //alert("resFieldId==="+resFieldId+"   &pidresFieldId==="+pidresFieldId);
            if(resFieldId != pidresFieldId ){
                $.ajax({
                    url: "${ctx}/"+Constants.saveFieldRestrictedUrl+"?entityId=${entityId}&fieldId=${fieldId}&resFieldId="+resFieldId+"&pidresFieldId="+pidresFieldId,
                    type: 'POST',
                    success: function(data){
                        var flag = data.error;
                        if(flag == "success"){
                            parent.closeTab(1);
                        }else if(flag == "error"){
                            alert("保存枚举值约束关系失败!");
                        }else{
                            alert(flag);
                        }
                    },
                    error: function() {
                        alert("操作失败");
                    }
                });
            }else{
                alert("设置未修改，与原有设置相同!");
            }
        }
    </script>
</head>
<body style="overflow:auto;" >
    <!-- 加载列表操作 -->
    <div id="buttonArray" class="button_list">
        <a href="javascript:;" onclick="saveRestrictAuth()">
                <span class="span_button">
                    <span><img src="${ctx}/image/common/operation/oper_SAVE.png"></span>
                    <span name="buTitle">保存</span>
                </span>
        </a>
        <a href="javascript:;" onclick="javascript:parent.closeTab();">
                <span class="span_button">
                    <span ><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                    <span name="buTitle" title="">取消</span>
                </span>
        </a>
    </div>

    <div class="drop-w" style="margin:5px;">
        <div class="drop-title">定义约束关系</div>
        <table id="RestrictTab" class="app_table" cellpadding="0" cellspacing="0" border="0" style="margin:5px;width:300px;">
            <tr>
                <td width="30%" style="text-align:center;text-indent: 0;">0</td>
                <td width="70%"><label><input name="resField" type="radio" value="0" <c:if test="${empty restricterId || restricterId == 0 }">checked="checked"</c:if> />&nbsp;不定义约束关系</label></td>
            </tr>
            <c:if test="${ !empty fieldList }">
                <c:forEach var="item" items="${fieldList}" varStatus="v">
                    <c:set var="hasRes" value="${ !empty restricterId and restricterId == item.id }" />
                    <tr>
                        <td style="text-align:center;text-indent: 0;">${v.count }</td>
                        <td>
                            <label>
                                <input name="resField" type="radio" value="${item.id }" <c:if test="${hasRes}" >checked="checked"</c:if>  />
                                &nbsp;${item.inchinese} <c:if test="${hasRes}" >（已选择）</c:if>
                            </label>
                        </td>
                    </tr>
                </c:forEach>
            </c:if>
        </table>
    </div>

</body>
</html>
